'use strict';

const Controller = require('egg').Controller;

class QuestionController extends Controller {
    async list() {
        let {ctx,service} = this;
        let list = await service.question.list();
        list = list.map(item => {
            item.options = item.options.split(',');
            return item
        })
        ctx.body = {
            code:1,
            data:list
        }
    }

    async answer(){
        let {ctx,service} = this;
        let {answer} = ctx.request.body;
        let trueAnswer = await service.question.answer();
        let count = 0;
        answer.forEach((item,index) => {
            console.log("========",item,trueAnswer[index].answer)
            if(item === trueAnswer[index].answer){
                count += 2;
            }
        })
        ctx.body = {
            code:1,
            data:count
        }
    }
}

module.exports = QuestionController;
